
package com.ruoyi.web.controller.lingshui.completion;


import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ruoyi.common.config.Global;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.supervise.domain.CompletionRecordApply;
import com.ruoyi.supervise.domain.CompletionRecordTable;
import com.ruoyi.supervise.domain.ProsAccess;
import com.ruoyi.supervise.service.ICompletionRecordService;
import com.ruoyi.supervise.service.IProsAccessService;
import com.ruoyi.system.domain.SysUser;

import cn.hutool.core.util.StrUtil;

/**
 * @ClassName: CompletionRecordController
 * @Description: 竣工备案controller
 * @Author wtj
 * @DateTime 2020年3月12日 下午5:10:51
 */
@Controller
@RequestMapping("/completion/completion")
public class CompletionRecordController extends BaseController{

	private String prefix = "lingshui/completion/reviewApply";
	
	@Autowired
    private ICompletionRecordService completionRecordService;
	
	@Autowired
    private IProsAccessService prosAccessService;
	
	/**
	 * @Title: completionRecord
	 * @Description: 跳转到待办管理页面
	 * @Author wtj
	 * @DateTime 2020-9-25 16:59:31
	 * @return
	 */
	@RequiresPermissions("completion:completion:view")
	@GetMapping()
	public String completionRecord()
	{
	    return prefix + "/completionRecord";
	}
	
	/**
	 * @Title: list
	 * @Description: 获取待办管理页面列表数据
	 * @Author wtj
	 * @DateTime 2020-9-25 16:59:52
	 * @param completionRecordTable
	 * @return
	 */
    @RequiresPermissions("completion:completion:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CompletionRecordTable completionRecordTable)
    {
        startPage();
        // 获取当前的用户信息
        SysUser currentUser = ShiroUtils.getSysUser();
        if(!currentUser.getLoginName().equals("admin") && !currentUser.getLoginName().trim().equals("lingshui")) {
        	completionRecordTable.setInChargeDepartmentGuid(currentUser.getDept().getGuid());
        }
        completionRecordTable.setState("已上报");
        List<CompletionRecordTable> completionRecordTableList=completionRecordService.selectCompletionRecordTableList(completionRecordTable);
        return getDataTable(completionRecordTableList);
    }
    
    /**
     * @Title: edit
     * @Description: 审批竣工备案
     * @Author wtj
     * @DateTime 2020年3月18日 上午11:03:40
     * @param guid
     * @param mmap
     * @return
     */
    @RequiresPermissions("completion:completion:apply")
    @GetMapping("/edit/{guid}")
    public String edit(@PathVariable("guid") String guid, ModelMap mmap)
    {
    	CompletionRecordApply cra = completionRecordService.selectCompletionRecordApplyByGuid(guid);
    	mmap.put("cra", cra);
    	mmap.put("startDate", DateUtils.parseDate(cra.getStartDate()));
    	mmap.put("endDate", DateUtils.parseDate(cra.getEndDate()));
    	List<ProsAccess> proAccessList=prosAccessService.selectCheckFileAndAccessByObjectId(guid);
    	for(ProsAccess pl:proAccessList) {
    		if(pl!=null) {
    			if(!StringUtils.isEmpty(pl.getAcceName())) {
    				String[] subStr=StrUtil.split(pl.getAcceName(), "|");
    				pl.setAcceName(Global.getConfig("ruoyi.bigPlatform")+subStr[1]);
        		}
    		}
    		
    	}
    	mmap.put("proAccessList", proAccessList);
    	mmap.put("isclose", "false");
        return prefix + "/completionRecordApply";
    }
    
    /**
     * @Title: detail
     * @Description: 获取申请表详情
     * @Author wtj
     * @DateTime 2020-9-25 17:00:42
     * @param guid
     * @param mmap
     * @return
     */
    @RequiresPermissions("completion:completion:apply")
    @GetMapping("/detail/{id}")
    public String detail(@PathVariable("id") String guid,ModelMap mmap)
    {
    	CompletionRecordApply cra = completionRecordService.selectCompletionRecordApplyByGuid(guid);
    	mmap.put("cra", cra);
    	mmap.put("startDate", DateUtils.parseDate(cra.getStartDate()));
    	mmap.put("endDate", DateUtils.parseDate(cra.getEndDate()));
    	List<ProsAccess> proAccessList=prosAccessService.selectCheckFileAndAccessByObjectId(guid);
    	for(ProsAccess pl:proAccessList) {
    		if(pl!=null) {
    			if(!StringUtils.isEmpty(pl.getAcceName())) {
    				String[] subStr=StrUtil.split(pl.getAcceName(), "|");
    				pl.setAcceName(Global.getConfig("ruoyi.bigPlatform")+subStr[1]);
        		}
    		}
    	}
    	mmap.put("proAccessList", proAccessList);
    	mmap.put("isclose", "false");
        return prefix + "/completionRecordApply";
    }
}
